package cn.zglbk.utils;

public final class Assert {
    /**
     * 是否是空数组
     * @param arr
     * @param e
     * @param <T>
     */
    public  static<T> void isEmptyArr(T[] arr,RuntimeException e){
        if(arr == null || arr.length == 0){
            throw e;
        }
    }

    /**
     * 数组长度是否一样
     * @param srcArr
     * @param destArr
     * @param e
     * @param <T>
     */
    public  static<T> void unlikeArrLen(T[] srcArr,T[] destArr,RuntimeException e){
        if(srcArr == null){
            if(destArr != null){
                throw e;
            }
        }
        if(destArr == null){
            if(srcArr != null){
                throw e;
            }
        }
        if(srcArr.length != destArr.length){
            throw e;
        }
    }
    public static void isNull(Object o,RuntimeException e){
        if(o == null){
            throw e;
        }
    }

    public Assert() {
    }

    public static void notNull(Object obj) {
        if (obj == null) {
            notNull(obj, "");
        }

    }

    public static void notNull(Object obj, String msg) {
        if (obj == null) {
            throw new IllegalArgumentException(msg);
        }
    }

    public static void notNull(Object obj, RuntimeException e) {
        if (obj == null) {
            throw e;
        }
    }

    public static void isTrue(boolean expression) {
        if (!expression) {
            isTrue(expression, "");
        }

    }

    public static void isTrue(boolean expression, String msg) {
        if (!expression) {
            throw new IllegalArgumentException(msg);
        }
    }

    public static void isTrue(boolean expression, RuntimeException e) {
        if (!expression) {
            throw e;
        }
    }
}
